package com.mcxx.modules.minimumliving.controller;

import com.alibaba.fastjson.JSON;
import com.mcxx.modules.minimumliving.service.BankService;
import com.mcxx.modules.minimumliving.service.FundPayService;
import com.mcxx.modules.miniSalvation.family.dto.BankAbutmentDTO;
import com.mcxx.modules.miniSalvation.family.dto.MessageDTO;
import com.mcxx.modules.miniSalvation.family.dto.SpeedProgressDTO;
import com.mcxx.modules.miniSalvation.family.entity.BankEntity;
import com.mcxx.modules.miniSalvation.family.param.BankParam;
import com.mcxx.modules.miniSalvation.family.service.read.BankReadService;
import com.mcxx.modules.miniSalvation.family.service.write.ImportBankService;
import com.mcxx.modules.miniSalvation.fundpay.dto.*;
import com.mcxx.modules.miniSalvation.fundpay.param.*;
import com.mcxx.modules.miniSalvation.fundpay.service.read.FundPayFamilyReadService;
import com.mcxx.modules.miniSalvation.fundpay.service.read.FundPayMemberReadService;
import com.mcxx.modules.miniSalvation.fundpay.service.read.FundPayReadService;
import com.mcxx.modules.miniSalvation.fundpay.service.write.FundPayFamilyWriteService;
import com.mcxx.modules.miniSalvation.fundpay.service.write.FundPayMemberWriteService;
import com.mcxx.result.BaseResult;
import com.mcxx.service.DefaultRestService;
import com.mcxx.util.*;
import com.yinhai.ta404.component.audit.vo.ExcelInfo;
import com.yinhai.ta404.core.restservice.annotation.RestService;
import com.yinhai.ta404.core.restservice.requestbean.PageParam;
import com.yinhai.ta404.core.restservice.resultbean.Page;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.validate.annotation.V;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.*;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Validated
@Api("补贴发放管理")
@RestService({"minimumliving/fundpay/v2"})
public class FundPayController extends DefaultRestService {
    private static final Logger logger = LoggerFactory.getLogger(FundPayController.class);

    @Autowired
    private FundPayService fundPayService;
    @Autowired
    private FundPayReadService fundPayReadService;
    @Autowired
    private FundPayFamilyReadService fundPayFamilyReadService;
    @Autowired
    private FundPayMemberReadService fundPayMemberReadService;
    @Resource
    private BankService bankService;
    @Autowired
    private ImportBankService importBankService;
    @Autowired
    private BankReadService bankReadService;
    @Autowired
    private FundPayMemberWriteService fundPayMemberWriteService;
    @Autowired
    private FundPayFamilyWriteService fundPayFamilyWriteService;


    @PostMapping("checkFundPayCanAddMember")
    @ApiOperation("检查名册是否能添加成员,返回值大于0表示不可以")
    public void checkFundPayCanAddMember(@V("notnull") String fundPayId){
        logger.info("检查名册是否能添加成员,参数fundPayId：{}", fundPayId);
        int rst = fundPayReadService.checkFundPayCanAddMember(fundPayId);
        setData(rst);
        logger.info("检查名册是否能添加成员,结果是：{}", rst);
    }




    @PostMapping("getCapitalFundPayList")
    @ApiOperation("获取保障金发放名册")
    public  void getCapitalFundPayList(FundPayListSearchParam fundPayListSearchParam, PageParam pageParam){
        logger.info("查询获取保障金发放名册,参数：{}", fundPayListSearchParam);

        fundPayListSearchParam.setBusinessType(Constant.BusinessCode.DIBAO);

        fundPayListSearchParam.setFundType(Constant.FundType.CAPITAL_FUND_PAY);

        Page page = fundPayReadService.getFundPayList(fundPayListSearchParam, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查询获取保障金发放名册,结果：{}", page);

    }


    @PostMapping("addCapitalFundPay")
    @ApiOperation("创建保障金发放名册")
    public void addCapitalFundPay(CapitalFundPayDTO capitalFundPayDTO){
        logger.info("创建保障金发放名册,参数：{}", capitalFundPayDTO);
        UserAccountVo user = this.getCurUserAccount();
        capitalFundPayDTO.setAreaCode(user.getAreaCode());
        capitalFundPayDTO.setOrgId(user.getOrgId());

        capitalFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);

        capitalFundPayDTO.setFundType(Constant.FundType.CAPITAL_FUND_PAY);

        capitalFundPayDTO.setPayType(Constant.FundType.CAPITAL_FUND_PAY);
        fundPayService.saveCapitalFundPay(capitalFundPayDTO,user);
        setData(true);
        logger.info("创建保障金发放名册,结果：{}", true);
    }


    @PostMapping("cancelCapitalFundPay")
    @ApiOperation("将保障金发放名册修改为撤销")
    @Deprecated
    public void cancelCapitalFundPay(@V("notnull") @RequestPart List<String>  fundPayIdList){
        logger.info("撤销保障金发放名册,id：{}", fundPayIdList);

        BaseResult<Map<String, List<String>>> result = fundPayService.cancelFundPay(fundPayIdList);
        if(result.isFail()) {
            setData(result.getMsg());
            return;
        }
        Map<String, List<String>> rstMap = result.getData();

        setData(packageRstMsg(rstMap));
        logger.info("撤销保障金发放名册,结果：{}", rstMap);
    }


    @PostMapping("verifyOrderNoticeState")
    @ApiOperation("验证保障金发放名册中是否存在未结束公示的")
    public void verifyOrderNoticeState(@V("notnull")String fundPayId){
        logger.info("验证保障金发放名册中是否存在未结束公示的,id：{}", fundPayId);
        int rst = fundPayFamilyReadService.verifyNoCompleteNotice(fundPayId);
        setData(rst);
        logger.info("验证保障金发放名册中是否存在未结束公示的,业务条数：{}", rst);
    }


    @PostMapping("confirmCapitalFundPay")
    @ApiOperation("将保障金发放名册状态修改为已确认")
    public void confirmCapitalFundPay(@V("notnull") String fundPayId){
        logger.info("确认保障金名册,id：{}", fundPayId);
        fundPayService.confirmFundPay(fundPayId, getCurUserAccount());
        logger.info("确认保障金名册,结果：{}", true);
    }


    @PostMapping("delCapitalFundPay")
    @ApiOperation("删除保障金发放名册")
    public void delCapitalFundPay(@V("notnull") @RequestPart List<String> fundPayIdList){
        logger.info("删除保障金发放名册,id：{}", fundPayIdList);

        BaseResult<Map<String, List<String>>> result = fundPayService.delFundPay(fundPayIdList);
        if(result.isFail()) {
            setData(result.getMsg());
            logger.info("删除保障金发放名册失败：" + result.getMsg());
            return;
        }
        Map<String, List<String>> rstMap = result.getData();

        setData(packageRstMsg(rstMap));
        logger.info("删除保障金发放名册,结果：{}", rstMap);
    }


    @PostMapping("delCapitalFundPayObjectList")
    @ApiOperation("删除已选保障金发放名册对象")
    public void delCapitalFundPayObjectList(@V("notnull") String fundPayId, @V("notnull") @RequestPart List<String> familyIdList){
        logger.info("删除已选保障金发放名册对象,参数：fundPayId->{},familyIdList->{}", fundPayId,familyIdList);
        fundPayService.delFundPayObjectList(fundPayId, familyIdList);
        setData(true);
        logger.info("删除已选保障金发放名册对象,结果是：{}", true);
    }


    @PostMapping("getNoSaveCapitalObjectList")
    @ApiOperation("获取未绑定名册的对象-保障金发放名册")
    public void getNoSaveCapitalObjectList( @V("notnull") CapitalFundPayDTO capitalFundPayDTO, @V("notnull") PageParam pageParam){
        logger.info("查看未进入保障金发放名册的对象--保障金发放名册,参数：{}", capitalFundPayDTO);

        capitalFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = fundPayService.getNoSaveCapitalObjectList(capitalFundPayDTO, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查看未进入保障金发放名册的对象--保障金发放名册,结果：{}", page);
    }


    @PostMapping("getCapitalObjectList")
    @ApiOperation("查询-保障金发放名册列表明细")
    public void getCapitalObjectList(@V("notnull") FundPayFamilyParam fundPayFamilyParam, @V("notnull") PageParam pageParam){
        logger.info("查看-保障金发放名册明细,参数：{}", fundPayFamilyParam);
        fundPayFamilyParam.setFundType(Constant.FundType.CAPITAL_FUND_PAY);

        fundPayFamilyParam.setBusinessType(Constant.BusinessCode.DIBAO);

        Page page = fundPayFamilyReadService.getFundPayFamilyList(fundPayFamilyParam, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查看-保障金发放名册明细,结果：{}", page);
    }


    @PostMapping("saveCapitalFundPayObject")
    @ApiOperation("添加已选保障金发放名册对象")
    public void saveCapitalFundPayObject(@V("notnull") String fundPayId, @V("notnull") Date payDate, @V("notnull") @RequestPart List<String> orderIdList){
        logger.info("保存已选保障金发放名册对象,参数：fundPayId->{}, orderIdList->{}", fundPayId, orderIdList);

        CapitalFundPayDTO capitalFundPayDTO = new CapitalFundPayDTO();
        capitalFundPayDTO.setId(fundPayId);
        capitalFundPayDTO.setPayDate(payDate);
        capitalFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);

        fundPayService.saveCapitalFundPayObject(capitalFundPayDTO, orderIdList);
        setData(true);
        logger.info("保存已选保障金发放名册对象,结果是：{}", true);
    }






    @PostMapping("getStandFundPayList")
    @ApiOperation("查询标准补发名册列表")
    public void getStandFundPayList(FundPayListSearchParam fundPayListSearchParam, PageParam pageParam){
        logger.info("查询标准补发名册列表,参数：{}", fundPayListSearchParam);

        fundPayListSearchParam.setBusinessType(Constant.BusinessCode.DIBAO);

        fundPayListSearchParam.setFundType(Constant.FundType.STAND_FUND_PAY);

        Page page = fundPayReadService.getFundPayList(fundPayListSearchParam, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查询标准补发名册列表,结果：{}", page);
    }


    @PostMapping("addStandFundPay")
    @ApiOperation("创建标准补发名册")
    public void addStandFundPay(@V("notnull")StandFundPayDTO standFundPayDTO){
        logger.info("创建标准补发名册,参数：{}", standFundPayDTO);
        UserAccountVo userAccountVo = this.getCurUserAccount();
        standFundPayDTO.setAreaCode(userAccountVo.getAreaCode());
        standFundPayDTO.setOrgId(userAccountVo.getOrgId());

        standFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);

        standFundPayDTO.setFundType(Constant.FundType.STAND_FUND_PAY);

        standFundPayDTO.setPayType(Constant.FundType.STAND_FUND_PAY);

        fundPayService.addStandFundPay(standFundPayDTO, userAccountVo);

        setData(true);
        logger.info("创建标准补发名册，结果是：{}", true);
    }


    @PostMapping("cancelStandFundPay")
    @ApiOperation("撤销标准补发名册")
    public void cancelStandFundPay(@V("notnull") @RequestPart List<String> fundPayIdList){
        logger.info("撤销补贴名册,id：{}", fundPayIdList);

        BaseResult<Map<String, List<String>>> result = fundPayService.cancelFundPay(fundPayIdList);
        if(result.isFail()) {
            setData(result.getMsg());
            return;
        }
        Map<String, List<String>> rstMap = result.getData();

        setData(packageRstMsg(rstMap));
        logger.info("撤销补贴名册,结果：{}", rstMap);
    }


    @PostMapping("confirmStandFundPay")
    @ApiOperation("确认标准补发名册")
    public void confirmStandFundPay(@V("notnull") String fundPayId){
        logger.info("确认补贴名册,id：{}", fundPayId);

        fundPayService.confirmFundPay(fundPayId, getCurUserAccount());
        setData(true);
        logger.info("确认补贴名册,结果：{}", true);
    }


    @PostMapping("delStandFundPay")
    @ApiOperation("删除标准补发名册")
    public void delStandFundPay(@V("notnull") @RequestPart List<String> fundPayIdList){
        logger.info("删除标准补发名册,id：{}", fundPayIdList);

        BaseResult<Map<String, List<String>>> result = fundPayService.delFundPay(fundPayIdList);
        if(result.isFail()) {
            setData(result.getMsg());
            logger.info("删除标准补发名册失败：" + result.getMsg());
            return;
        }
        Map<String, List<String>> rstMap = result.getData();

        setData(packageRstMsg(rstMap));
        logger.info("删除标准补发名册,结果：{}", rstMap);
    }


    @PostMapping("delStandFundPayObjectList")
    @ApiOperation("删除已选标准补发对象")
    public void delStandFundPayObjectList(@V("notnull") String fundPayId, @V("notnull") @RequestPart  List<String> familyIdList){
        logger.info("删除已选标准补发对象,参数：fundPayId->{},familyIdList->{}", fundPayId, familyIdList);
        fundPayService.delFundPayObjectList(fundPayId, familyIdList);
        setData(true);
        logger.info("删除已选标准补发对象,结果是：{}", true);
    }


    @PostMapping("getNoSaveStandObjectList")
    @ApiOperation("查询可以加入到标准补发名册的成员列表")
    public void getNoSaveStandObjectList(@V("notnull") StandFundPayDTO standFundPayDTO, @V("notnull") PageParam pageParam){
        logger.info("查看可以加入标准补发名册的业务,参数：{}", standFundPayDTO);
        standFundPayDTO.setFundType(Constant.FundType.STAND_FUND_PAY);
        standFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = fundPayService.getNoSaveStandObjectList(standFundPayDTO, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查看可以加入标准补发名册的业务,结果：{}", page);
    }


    @PostMapping("getStandObjectList")
    @ApiOperation("查看标准补发名册明细")
    public void getStandObjectList(@V("notnull")FundPayFamilyParam fundPayFamilyParam, PageParam pageParam){
        logger.info("查看标准补发名册明细,参数：{}", fundPayFamilyParam);
        fundPayFamilyParam.setFundType(Constant.FundType.STAND_FUND_PAY);
        fundPayFamilyParam.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = fundPayFamilyReadService.getFundPayFamilyList(fundPayFamilyParam, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查看标准补发名册明细,结果：{}", page);
    }


    @PostMapping("saveStandObjectList")
    @ApiOperation("保存已选标准补发对象")
    public void saveStandObjectList(@V("notnull") String fundPayId, @V("notnull") Date payDate, @V("notnull") @RequestPart List<String> orderIdList){
        logger.info("保存已选标准补发对象,参数：fundPayId->{},orderIdList->{}", fundPayId,orderIdList);

        StandFundPayDTO standFundPayDTO = new StandFundPayDTO();
        standFundPayDTO.setId(fundPayId);
        standFundPayDTO.setPayDate(payDate);
        standFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);

        fundPayService.saveStandObjectList(standFundPayDTO, orderIdList);
        setData(true);
        logger.info("保存已选标准补发对象,结果是：{}", true);
    }







    @PostMapping("getAllowanceFundPayList")
    @ApiOperation("补贴名册列表页查询")
    public void getAllowanceFundPayList(FundPayListSearchParam fundPayListSearchParam, PageParam pageParam){
        logger.info("补贴名册列表页查询,参数：{}", fundPayListSearchParam);

        fundPayListSearchParam.setBusinessType(Constant.BusinessCode.DIBAO);

        fundPayListSearchParam.setFundType(Constant.FundType.ALLOWANCE_FUND_PAY);

        Page page = fundPayReadService.getFundPayList(fundPayListSearchParam, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("补贴名册列表页查询,结果：{}", page);
    }


    @PostMapping("addAllowanceFundPay")
    @ApiOperation("创建补贴名册")
    public void addAllowanceFundPay(@Valid AllowanceFundPayDTO allowanceFundPayDTO){
        logger.info("创建补贴名册,参数：{}", allowanceFundPayDTO);
        UserAccountVo user = this.getCurUserAccount();

        allowanceFundPayDTO.setAreaCode(getCurUserAccount().getAreaCode());
        allowanceFundPayDTO.setOrgId(user.getOrgId());

        allowanceFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);

        allowanceFundPayDTO.setFundType(Constant.FundType.ALLOWANCE_FUND_PAY);

        allowanceFundPayDTO.setPayType(Constant.FundType.ALLOWANCE_FUND_PAY);

        fundPayService.addAllowanceFundPay(allowanceFundPayDTO, user);
        setData(true);
        logger.info("创建补贴名册，结果是：{}", true);
    }


    @PostMapping("cancelAllowanceFundPay")
    @ApiOperation("撤销补贴名册")
    public void cancelAllowanceFundPay(@V("notnull") @RequestPart List<String> fundPayIdList){
        logger.info("撤销补贴名册,id：{}", fundPayIdList);

        BaseResult<Map<String, List<String>>> result = fundPayService.cancelFundPay(fundPayIdList);
        if(result.isFail()) {
            setData(result.getMsg());
            return;
        }
        Map<String, List<String>> rstMap = result.getData();

        setData(packageRstMsg(rstMap));
        logger.info("撤销补贴名册,结果：{}", rstMap);
    }


    @PostMapping("confirmAllowanceFundPay")
    @ApiOperation("撤销补贴名册")
    public void confirmAllowanceFundPay(@V("notnull") String fundPayId){
        logger.info("确认补贴名册,id：{}", fundPayId);

        fundPayService.confirmFundPay(fundPayId, getCurUserAccount());

        setData(true);
        logger.info("确认补贴名册,结果：{}", true);
    }


    @PostMapping("verifySyncFundpay")
    @ApiOperation("检查发放名册是否可以同步数据")
    public void verifySyncFundpay(@V("notnull") String fundPayId){
        logger.info("同步发放名册至财政发放系统前，检查发放名册是否可以同步数据到发放系统,id：{}", fundPayId);
        String msg = fundPayService.checkCanSyncFundpayData(fundPayId);
        logger.info("结果：" + msg);
        setData(msg);
    }


    @PostMapping("syncFundpayData")
    @ApiOperation("同步发放名册至财政发放系统")
    public void syncFundpayData(@V("notnull") String fundPayId){
        logger.info("同步发放名册至财政发放系统,id：{}", fundPayId);
        String msg = fundPayService.syncFundpayData(fundPayId);
        logger.info("结果：" + msg);
        setData(msg);
    }


    @PostMapping("getFundpayExceptionList")
    @ApiOperation("查看该名册异常数据")
    public void getFundpayExceptionList(@V("notnull") String fundPayId, PageParam pageParam){
        logger.info("根据名册查看该名册生成过程中是否存在异常情况,id：{}", fundPayId);
        Page page = fundPayService.getPageFundpayException(fundPayId, pageParam);
        logger.info("结果：" + page.getPageSize());
        setPageBean(page);
    }


    @PostMapping("confirmFundpayException")
    @ApiOperation("确认发放名册异常记录")
    public void confirmFundpayException(@V("notnull") @RequestPart List<String> exceptionIds){
        logger.info("确认发放名册异常记录, ids：{}", exceptionIds);
        Integer count = fundPayService.confirmFundpayException(exceptionIds);
        logger.info("已确认条数：{}", count);
        setData(String.format("已确认，总计：%d条", count));
    }


    @PostMapping({"downloadExceptionList"})
    public void downLoadRescueList(HttpServletResponse response, @RequestBody FundPayParam param) throws IOException {
        ExcelInfo excelInfo = fundPayService.exportExcel(param.getFundPayId());
        if(null != excelInfo){
            ZipInfoUtil.exportZipResponse(response, excelInfo, this.getCurUserId());
        }
    }


    @PostMapping("delAllowanceFundPay")
    @ApiOperation("删除名册")
    public void delAllowanceFundPay(@V("notnull") @RequestPart List<String> fundPayIdList){
        logger.info("删除名册,id：{}", fundPayIdList);

        BaseResult<Map<String, List<String>>> result = fundPayService.delFundPay(fundPayIdList);
        if(result.isFail()) {
            setData(result.getMsg());
            logger.info("删除名册失败：" + result.getMsg());
            return;
        }
        Map<String, List<String>> rstMap = result.getData();

        setData(packageRstMsg(rstMap));
        logger.info("删除名册,结果：{}", rstMap);
    }


    @PostMapping("delAllowanceMember")
    @ApiOperation("删除补贴名册对象")
    public void delAllowanceMember(@V("notnull") String fundPayId, @V("notnull") @RequestPart List<String> memberIdList){
        logger.info("删除补贴名册对象,参数：fundPayId->{}, memberIdList ->{}", fundPayId, memberIdList);
        fundPayService.delAllowanceMember(fundPayId, memberIdList);
        setData(true);
        logger.info("删除补贴名册对象,结果是：{}", true);
    }


    @PostMapping("getNoSaveAllowanceMemberList")
    @ApiOperation("查询新增补贴名册对象列表(未保存到名册的成员)")
    public void getNoSaveAllowanceMemberList(AllowanceFundPayDTO allowanceFundPayDTO, PageParam pageParam){
        logger.info("查询新增补贴名册对象列表(未保存到名册的成员),参数：{}", allowanceFundPayDTO);
        allowanceFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = fundPayService.getNoSaveAllowanceMemberList(allowanceFundPayDTO, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查询新增补贴名册对象列表(未保存到名册的成员),结果：{}", page);
    }


    @PostMapping("getAllowanceFundPayDetail")
    @ApiOperation("查看补贴名册明细")
    public void getAllowanceFundPayDetail(FundPayMemberParam fundPayMemberParam, PageParam pageParam){
        logger.info("查看补贴名册明细,参数：{}", fundPayMemberParam);
        fundPayMemberParam.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = fundPayMemberReadService.getAllowanceFundPayMember(fundPayMemberParam, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查看补贴名册明细,结果：{}", page);
    }


    @PostMapping("addAllowanceMember")
    @ApiOperation("添加补贴名册对象-成员")
    public void addAllowanceMember(@V("notnull") String fundPayId,
                                          @V("notnull") @RequestPart List<String> memberIdList,
                                          @V("notnull") @RequestPart List<String> orderIdList){
        logger.info("添加补贴名册对象-成员,参数：fundPayId->{},memberIdList->{}", fundPayId, memberIdList);
        fundPayService.addAllowanceMember(fundPayId, orderIdList, memberIdList);
        setData(true);
        logger.info("添加补贴名册对象-成员,结果是：{}", true);
    }


    @PostMapping("addAllowanceFundPayFamily")
    @ApiOperation("添加补贴名册对象-家庭")
    public void addAllowanceFundPayFamily(@V("notnull") String fundPayId,
                                   @V("notnull") @RequestPart List<String> familyIdList,
                                   @V("notnull") @RequestPart List<String> orderIdList){
        logger.info("添加补贴名册对象-成员,参数：fundPayId->{},familyIdList->{}", fundPayId, familyIdList);
        fundPayService.addAllowanceFundPayFamily(fundPayId, orderIdList, familyIdList);
        setData(true);
        logger.info("添加补贴名册对象-成员,结果是：{}", true);
    }


    @PostMapping("getNoSaveAllowanceFamilyList")
    @ApiOperation("查询新增补贴名册对象列表(未保存到名册的家庭)")
    public void getNoSaveAllowanceFamilyList(AllowanceFundPayDTO allowanceFundPayDTO, PageParam pageParam){
        logger.info("查询新增补贴名册对象列表(未保存到名册的成员),参数：{}", allowanceFundPayDTO);
        allowanceFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = fundPayService.getNoSaveAllowanceMemberList(allowanceFundPayDTO, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查询新增补贴名册对象列表(未保存到名册的成员),结果：{}", page);
    }


    @PostMapping("delAllowanceFundPayFamily")
    @ApiOperation("删除补贴名册对象")
    public void delAllowanceFundPayFamily(@V("notnull") String fundPayId, @V("notnull") @RequestPart List<String> familyIdList){
        logger.info("删除补贴名册对象,参数：fundPayId->{}, familyIdList ->{}", fundPayId, familyIdList);
        fundPayService.delAllowanceFundPayFamily(fundPayId, familyIdList);
        setData(true);
        logger.info("删除补贴名册对象,结果是：{}", true);
    }


    @PostMapping({"downLoadFundPayFamilyList"})
    public void downLoadFundPayFamilyList(HttpServletResponse response,@RequestBody FundPayParam param) throws IOException {
        ExcelInfo excelInfo = fundPayService.exportExcelFundPayFamily(param.getExportType(),param.getIdsList(),param,getCurUserAccount());
        if(null != excelInfo){
            FileExportUtil.exportFileResponse(response, excelInfo, getCurUserAccount().getAreaName());
        }
    }


    private String packageRstMsg(Map<String, List<String>> rstMap){
        StringBuffer rstMsg = new StringBuffer();
        if(rstMap.containsKey("success")){
            rstMsg.append("成功【").append(rstMap.get("success").size()).append("】条\n");
        }
        if(rstMap.containsKey("fail")){
            rstMsg.append("失败【").append(rstMap.get("fail").size()).append("】条");
        }
        return rstMsg.toString();
    }







    @PostMapping("getCustomFundPayList")
    @ApiOperation("自定义补发名册列表页查询")
    public void getCustomFundPayList(FundPayListSearchParam fundPayListSearchParam, PageParam pageParam){

        logger.info("自定义补发名册列表页查询,参数：{}", fundPayListSearchParam);

        fundPayListSearchParam.setBusinessType(Constant.BusinessCode.DIBAO);

        fundPayListSearchParam.setFundType(Constant.FundType.CUSTOM_FUND_PAY);

        Page page = fundPayReadService.getFundPayList(fundPayListSearchParam, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("自定义补发名册列表页查询,结果：{}", page);
    }


    @PostMapping("addCustomFundPay")
    @ApiOperation("创建自定义补发名册")
    public void addCustomFundPay(@V CustomFundPayDTO customFundPayDTO){
        logger.info("自定义补发名册列表页查询,参数：{}", customFundPayDTO);
        UserAccountVo userAccountVo = this.getCurUserAccount();

        customFundPayDTO.setAreaCode(userAccountVo.getAreaCode());
        customFundPayDTO.setOrgId(userAccountVo.getOrgId());

        customFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);

        customFundPayDTO.setFundType(Constant.FundType.CUSTOM_FUND_PAY);

        customFundPayDTO.setPayType(Constant.FundType.CUSTOM_FUND_PAY);

        fundPayService.addCustomFundPay(customFundPayDTO, userAccountVo);
        setData(true);
        logger.info("创建自定义补发名册,结果：{}", true);
    }


    @PostMapping("delCustomFundPay")
    @ApiOperation("删除自定义补发名册")
    public void delCustomFundPay(@V("notnull") @RequestPart List<String> customFundPayIdList){
        logger.info("删除自定义补发名册,参数customFundPayIdList：{}", customFundPayIdList);

        BaseResult<Map<String, List<String>>> result = fundPayService.delFundPay(customFundPayIdList);
        if(result.isFail()) {
            setData(result.getMsg());
            logger.info("删除自定义补发名册失败：" + result.getMsg());
            return;
        }
        Map<String, List<String>> rstMap = result.getData();

        setData(packageRstMsg(rstMap));
        logger.info("删除自定义补发名册,结果：{}", rstMap);
    }


    @PostMapping("cancelCustomFundPay")
    @ApiOperation("撤销自定义补发名册")
    public void cancelCustomFundPay(@V("notnull") @RequestPart List<String> customFundPayIdList){
        logger.info("撤销自定义补发名册,参数customFundPayIdList：{}", customFundPayIdList);

        BaseResult<Map<String, List<String>>> result = fundPayService.cancelFundPay(customFundPayIdList);
        if(result.isFail()) {
            setData(result.getMsg());
            return;
        }
        Map<String, List<String>> rstMap = result.getData();

        setData(packageRstMsg(rstMap));
        logger.info("撤销自定义补发名册,结果：{}", rstMap);
    }


    @PostMapping("verifyConfirmCustom")
    @ApiOperation("验证保障金发放名册中是否存在未结束公示的")
    public void verifyConfirmCustom(@V("notnull")String fundPayId){
        logger.info("验证是否存在未结束的公示；是否有补发金额为0的,id：{}", fundPayId);
        String rst = fundPayService.verifyConfirmCustom(fundPayId);
        setData(rst);
        logger.info("验证是否存在未结束的公示；是否有补发金额为0的,结果：{}", rst);
    }


    @PostMapping("confirmCustomFundPay")
    @ApiOperation("确认自定义补发名册")
    public void confirmCustomFundPay(@V("notnull") String fundPayId){
        logger.info("确认自定义补发名册,参数：{}");

        fundPayService.confirmCustomFundPay(fundPayId, getCurUserAccount());

        setData(true);
        logger.info("确认自定义补发名册,结果：{}", true);
    }


    @PostMapping("getNoSaveCustomMemberList")
    @ApiOperation("查询新增自定义补发名册对象列表(未保存到名册的成员列表)")
    public void getNoSaveCustomMemberList(@V CustomFundPayDTO customFundPayDTO, PageParam pageParam){
        logger.info("查询新增自定义补发名册对象列表(未保存到名册的成员列表),参数：{}");
        customFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = fundPayMemberReadService.getNoSaveCustomMemberList(customFundPayDTO, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查询新增自定义补发名册对象列表(未保存到名册的成员列表),结果：{}", page);
    }


    @PostMapping("getNoSaveCustomFamilyList")
    @ApiOperation("查询新增自定义补发名册对象列表(未保存到名册的成员列表)")
    public void getNoSaveCustomFamilyList(@V CustomFundPayDTO customFundPayDTO, PageParam pageParam){
        logger.info("查询新增自定义补发名册对象列表(未保存到名册的成员列表),参数：{}");
        customFundPayDTO.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = fundPayFamilyReadService.getNoSaveCustomFamilyList(customFundPayDTO, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查询新增自定义补发名册对象列表(未保存到名册的成员列表),结果：{}", page);
    }


    @PostMapping("getCustomMemberList")
    @ApiOperation("查看自定义补发名册明细-按分类救助金发放")
    public void getCustomMemberList(FundPayFamilyParam fundPayFamilyParam, PageParam pageParam){
        logger.info("查看自定义补发名册明细-按分类救助金发放,参数：{}", fundPayFamilyParam);
        fundPayFamilyParam.setFundType(Constant.FundType.CUSTOM_FUND_PAY);
        fundPayFamilyParam.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = fundPayMemberReadService.getCustomMemberList(fundPayFamilyParam, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查看自定义补发名册明细-按分类救助金发放,结果：{}", page);
    }


    @PostMapping("getCustomFamilyList")
    @ApiOperation("查询-保障金发放名册列表明细")
    public void getCustomFamilyList(@V("notnull") FundPayFamilyParam fundPayFamilyParam, @V("notnull") PageParam pageParam){
        logger.info("查看自定义补发名册明细-按基本救助金发放,参数：{}", fundPayFamilyParam);
        fundPayFamilyParam.setFundType(Constant.FundType.CUSTOM_FUND_PAY);

        fundPayFamilyParam.setBusinessType(Constant.BusinessCode.DIBAO);

        Page page = fundPayFamilyReadService.getFundPayFamilyList(fundPayFamilyParam, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("查看自定义补发名册明细-按基本救助金发放,结果：{}", page);
    }


    @PostMapping("updateMemberFundNumber")
    @ApiOperation("修改补发金额")
    public void updateMemberFundNumber(@V("notnull")String fundPayMemberId, @V("notnull")String fundPayFamilyId,
                                       @V("notnull")String fundPayId, @V("notnull")double fundNumber){
        logger.info("修改补发金额,参数fundPayMemberId：{},fundNumber:{}", fundPayMemberId, fundNumber);
        fundPayService.updateCustomMemberFundNumber(fundPayMemberId, fundPayFamilyId, fundPayId, fundNumber);
        setData(true);
        logger.info("修改补发金额,结果是：{}", true);
    }


    @PostMapping("updateFamilyFundNumber")
    @ApiOperation("修改补发金额")
    public void updateFamilyFundNumber(@V("notnull")String fundPayFamilyId,
                                       @V("notnull")String fundPayId, @V("notnull")double fundNumber){
        logger.info("修改补发金额,参数fundPayMemberId：{},fundNumber:{}", fundPayFamilyId, fundNumber);
        fundPayService.updateCustomFamilyFundNumber(fundPayFamilyId, fundPayId, fundNumber);
        setData(true);
        logger.info("修改补发金额,结果是：{}", true);
    }


    @PostMapping("updateMemberRemark")
    @ApiOperation("修改成员备注")
    public void updateMemberRemark(@V("notnull")String fundPayMemberId, String remark){
        logger.info("修改成员备注,参数fundPayMemberId：{}, remark:{}", fundPayMemberId, remark);
        fundPayMemberWriteService.updateRemark(fundPayMemberId, remark);
        setData(true);
        logger.info("修改成员备注,结果是：{}", true);
    }


    @PostMapping("updateFamilyRemark")
    @ApiOperation("修改家庭备注")
    public void updateFamilyRemark(@V("notnull")String fundPayFamilyId, String remark){
        logger.info("修改家庭备注,参数fundPayFamilyId：{}, remark:{}", fundPayFamilyId, remark);
        fundPayFamilyWriteService.updateCustomFamilyRemark(fundPayFamilyId, remark);
        setData(true);
        logger.info("修改家庭备注,结果是：{}", true);
    }


    @PostMapping("addCustomMember")
    @ApiOperation("添加自定义补发名册对象")
    public void addCustomMember(@V("notnull") String fundPayId,
                                @V("notnull") @RequestPart List<String> memberIdList,
                                @V("notnull") @RequestPart List<String> orderIdList){

        logger.info("添加自定义补发名册对象-成员,参数：fundPayId->{},memberIdList->{},orderIdList->{}", fundPayId, memberIdList, orderIdList);
        fundPayService.addCustomMember(fundPayId, orderIdList, memberIdList);
        setData(true);
        logger.info("添加自定义补发名册对象结束-成员,结果是：{}", true);
    }


    @PostMapping("addCustomFamily")
    @ApiOperation("添加自定义补发名册对象")
    public void addCustomFamily(@V("notnull")String fundPayId, @V("notnull") @RequestPart List<String> orderIdList){
        logger.info("添加自定义补发名册对象,参数fundPayId：{}, orderIdList:{}", fundPayId, orderIdList);
        fundPayService.addCustomFamily(fundPayId, orderIdList);
        setData(true);
        logger.info("添加自定义补发名册对象结束");
    }


    @PostMapping("delCustomMember")
    @ApiOperation("添加自定义补发名册对象")
    public void delCustomMember(@V("notnull") String fundPayId, @V("notnull") @RequestPart List<String> memberIdList){
        logger.info("删除自定义补发名册成员-按基本救助金删除成员,参数：fundPayId->{}, memberIdList ->{}", fundPayId, memberIdList);
        fundPayService.delCustomMember(fundPayId, memberIdList);
        setData(true);
        logger.info("删除自定义补发名册成员-按基本救助金删除成员结束");
    }


    @PostMapping("delCustomFamily")
    @ApiOperation("添加自定义补发名册对象")
    public void delCustomFamily(@V("notnull") String fundPayId, @V("notnull") @RequestPart List<String> familyIdList){
        logger.info("删除自定义补发名册家庭-按基本救助金删除家庭,参数fundPayId：{}, orderIdList:{}", fundPayId, familyIdList);
        fundPayService.delCustomFamily(fundPayId, familyIdList);
        setData(true);
        logger.info("删除自定义补发名册家庭-按基本救助金删除家庭结束");
    }


    @PostMapping("importCustomFundPayObjects")
    @ApiOperation("导入自定义补发名册对象")
    public void importCustomFundPayObjects( @RequestPart("file") MultipartFile file, @V("notnull") String customFundPayId){
        logger.info("添加自定义补发名册对象,参数customFundPayId：{}", customFundPayId);
        String rstMsg = fundPayMemberWriteService.importCustomFundPayObjects(customFundPayId, file, getCurUserAccount());
        setData(rstMsg);
        logger.info("添加自定义补发名册对象,结果：{}", true);
    }








    @PostMapping("getFuneralFundPayList")
    @ApiOperation("补贴名册列表页查询")
    public void getFuneralFundPayList(FundPayListSearchParam fundPayListSearchParam, PageParam pageParam){
        logger.info("补贴名册列表页查询,参数：{}", fundPayListSearchParam);

        fundPayListSearchParam.setBusinessType(Constant.BusinessCode.DIBAO);


        Page page = fundPayReadService.getFundPayList(fundPayListSearchParam, pageParam, getCurUserAccount());
        this.setPageBean(page);
        logger.info("补贴名册列表页查询,结果：{}", page);
    }





    @PostMapping("getMonitorDataList")
    @ApiOperation("监测提醒查询")
    public void getMonitorDataList(MonitorDataParam param, PageParam pageParam){
        logger.info("监测提醒查询 参数 ", JSON.toJSONString(param));
       param.setBusinessCode(Constant.BusinessCode.DIBAO);
          setPageBean(fundPayReadService.getMonitorDataList(param,pageParam,getCurUserAccount()));
    }





    @PostMapping(value = "getBankPage")
    @ApiOperation(value = "银行账号按条件查询")
    public void getBankPage(BankParam param, PageParam pageParam) {
        param.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = bankService.getBankPage(getCurUserAccount(), param, pageParam);
        this.setPageBean(page);
    }



    @PostMapping(value = "getBankPageMin")
    @ApiOperation(value = "银行账号按条件查询")
    public void getBankPageMin(BankParam param, PageParam pageParam) {
        param.setBusinessType(Constant.BusinessCode.DIBAO);
        Page page = bankService.getBankPageMin(getCurUserAccount(), param, pageParam);
        this.setPageBean(page);
    }


    @PostMapping(value = "getBankById")
    @ApiOperation(value = "根据银行账号ID查询银行账号信息")
    public void getBankById(String id) {
        logger.info("根据id查询对应的银行卡信息，参数是:{}", id);
        BankEntity bankEntity = bankService.getBankById(id);
        setData(bankEntity);
        logger.info("根据id查询对应的银行卡信息，结果是:{}", bankEntity);
    }



    @PostMapping(value = "getBankByFamilyId")
    @ApiOperation(value = "根据家庭id查询银行账号信息")
    public void getBankByFamilyId(String familyId,String memberId) {
        logger.info("根据id查询对应的银行卡信息，参数是:{}", familyId);
        BankEntity bankEntity = bankService.getBankByFamilyId(familyId,memberId,Constant.BusinessCode.DIBAO);
        setData(bankEntity);
        logger.info("根据id查询对应的银行卡信息，结果是:{}", bankEntity);
    }


    @PostMapping(value = "updateBankInfo")
    @ApiOperation(value = "维护救助对象的银行账号，保存更新")
    public void updateBankAccountInfo(BankEntity bankEntity) {
        logger.info("维护救助对象的银行账号，保存更新，参数是:{}", bankEntity);
        bankEntity.setBusinessType(Constant.BusinessCode.DIBAO);
        bankService.updateBankInfo(bankEntity,getCurUserAccount());
        logger.info("维护救助对象的银行账号，保存更新，参数是:{}", true);
        setData(true);
    }


    @PostMapping({"downLoadBankTemplate"})
    public void downLoadBankTemplate(HttpServletResponse response) throws IOException {
        logger.info("下载银行账号开始");
        InputStream resourceAsStream = this.getClass().getResourceAsStream("/bakhtml/yinhangmoban.xlsx");
        byte[] byt = IOUtils.toByteArray(resourceAsStream);

        logger.info("二进制文件:{}", byt);
        ZipInfoUtil.exportZipByte(response,"bankTemplate.xlsx", byt, this.getCurUserId());
        logger.info("下载银行账号结束");
    }


    @PostMapping(value = "importIntoBankAccount")
    @ApiOperation(value = "批量导入银行账号")
    public void importIntoBankAccount(@RequestParam("file") MultipartFile file) {
        if (CommonUtil.invalidArgs(file)) {
            setError(FailureCode.ERR_10000.getMessage());
        }
        try {
            BaseResult<MessageDTO> result = importBankService.importIntoBankAccount(file,file.getInputStream(),getCurUserAccount(),Constant.BusinessCode.DIBAO);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @PostMapping(value = "getBankAccountImportProgress")
    @ApiOperation(value = "查看导入进度")
    public void getSpeedProgress() {
        BaseResult<List<SpeedProgressDTO>> result = bankService.getSpeedProgress(Constant.BusinessCode.DIBAO,getCurUserAccount().getUserId());
        setData(result.getData());
    }


    @PostMapping({"downLoadFundPayList"})
    public void downLoadFundPayListt(HttpServletResponse response,@RequestBody FundPayParam param) throws IOException {
        ExcelInfo excelInfo = fundPayService.exportExcelFundPay(param.getExportType(),param.getIdsList(),param,getCurUserAccount());
        if(null != excelInfo){
            FileExportUtil.exportFileResponse(response, excelInfo, getCurUserAccount().getAreaName());
//            ZipInfoUtil.exportZipResponse(response, excelInfo, this.getCurUserId());
        }
    }


    @PostMapping({"downCapitalObjectList"})
    public void downCapitalObjectList(HttpServletResponse response,@RequestBody FundPayFamilyParam param) throws IOException {
        param.setBusinessType(Constant.BusinessCode.DIBAO);
        ExcelInfo excelInfo = fundPayService.exportExcelCapitalObjectList(param,getCurUserAccount());
        if(null != excelInfo){
            FileExportUtil.exportFileResponse(response, excelInfo, getCurUserAccount().getAreaName());
//            ZipInfoUtil.exportZipResponse(response, excelInfo, this.getCurUserId());
        }
    }


    @PostMapping("bankMemberIdCardCheck")
    @ApiOperation(value="银行卡代理人的身份证验证", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,notes="银行卡代理人的身份证验证")
    public void bankMemberIdCardCheck(@V({"notnull"})  String accountIdcard){
         bankReadService.bankMemberIdCardCheck(accountIdcard);
    }


    @PostMapping({"downBankList"})
    public void downBankList(HttpServletResponse response,@RequestBody BankParam param) throws IOException {
        param.setBusinessType(Constant.BusinessCode.DIBAO);
        ExcelInfo excelInfo = bankService.exportBank(param,getCurUserAccount());
        if(null != excelInfo){
            FileExportUtil.exportFileResponse(response, excelInfo, getCurUserAccount().getAreaName());
//            ZipInfoUtil.exportZipResponse(response, excelInfo, this.getCurUserId());
        }
    }


    @GetMapping("gainBankInfo")
    @ApiOperation("获取财政银行卡信息")
    public void gainBankInfo(@Validated BankAbutmentDTO dto) {
        logger.info("开始获取财政银行卡信息，参数是：{}", dto);
        Map<String, String> map = fundPayService.gainBankInfo(dto,getCurUserAccount());
        setData(map);

        logger.info("获取财政银行卡信息结束");
    }


    @PostMapping({"downLoadCustomImportTemplate"})
    public void downLoadCustomImportTemplate(HttpServletResponse response) throws IOException {
        logger.info("下载自定义补发导入模板");
        InputStream resourceAsStream = this.getClass().getResourceAsStream("/bakhtml/customImportTemplate.xls");
        byte[] byt = new byte[resourceAsStream.available()];
        byt = IOUtils.toByteArray(resourceAsStream);

        logger.info("二进制文件:{}", byt);
        ZipInfoUtil.exportZipByte(response,"自定义补发导入模板.xls", byt, this.getCurUserId());
        logger.info("下载自定义补发导入模板结束");
    }
}
